/** @file oal_dnld.h
  *
  * @brief This file contains ar8030 firmware download defines.
  *
  *  Copyright (C) 2024, Artosyn Technologies. ALL RIGHTS RESERVED.
  *
  *  This Information is proprietary to Artosyn Technologies and MAY NOT
  *  be copied by any method or incorporated into another program without
  *  the express written consent of Artosyn. This Information or any portion
  *  thereof remains the property of Artosyn. The Information contained herein
  *  is believed to be accurate and Artosyn assumes no responsibility or
  *  liability for its use in any way and conveys no license or title under
  *  any patent or copyright and makes no representation or warranty that this
  *  Information is free from patent or copyright infringement.
  *
  */
#ifndef _OAL_DNLD_H_
#define _OAL_DNLD_H_

#include <linux/kernel.h>
#include "oal_main.h"

/** SPL load addr */
#define SPL_HEADER_LOAD_ADDR    (0x002f0000 + 0x40)
/** SPL header size */
#define SPL_HEADER_MAX_SIZE     (512)
/** SPL align size */
#define SPL_IMAGE_SIZE_ALIGN    (512)

#define ROUNDUP(x, y)           (((x) + ((y) - 1)) & ~((y) - 1))

#pragma pack(push)
#pragma pack(1)

/** Structure of firmware file header */
typedef struct
{
    unsigned int    magic;
    unsigned short  img_type;
    unsigned short  header_len;
    unsigned int    header_checksum;
    unsigned int    img_version;
    unsigned int    flag;
    unsigned int    boot_info;
    unsigned int    spl_load_addr;
    unsigned int    spl_len;
    unsigned int    troot_load_addr;
    unsigned int    troot_len;
    unsigned int    signature_load_addr;
    unsigned int    signature_len;
    unsigned int    spl_dtb_offset;
    unsigned long   checksum;
    unsigned int    id_masks;
    unsigned char   patch_len[8];
    //unsigned char   patch[0];
}STRU_SPL_HEADER;

#pragma pack(pop)

/**
 *  @brief Download the firmware to ar8030
 *
 *  @param handle   A pointer to oal_handle structure
 *
 *  @return         OAL_STATUS_SUCCESS or OAL_STATUS_FAILURE
 */
oal_status oal_init_fw(oal_handle *handle);

#endif